<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/10/10 0010
 * Time: 上午 9:15
 */

namespace app\admin\controller;


use controller\BasicAdmin;
use service\DataService;
use think\Db;

class NewsCate extends BasicAdmin
{
    public $table = 'NewsCate';
    public function index(){
        $this->title = '栏目';
        $db = Db::name($this->table)->hidden('linian,lesson,footer')->where(['is_deleted'=>1])->order('sort desc,id desc');
        return parent::_list($db,false);
    }

    public function cate_add(){
        $this->title = '分栏详情';
        return $this->_form($this->table);
    }


    /**
     * 分类禁用
     * @throws \think\Exception
     * @throws \think\exception\PDOException
     */
    public function forbid()
    {
        if (DataService::update($this->table)) {
            $this->success("分类禁用成功！", '');
        }
        $this->error("分类禁用失败，请稍候再试！");
    }

    /**
     * 分类启用
     * @throws \think\Exception
     * @throws \think\exception\PDOException
     */
    public function resume()
    {
        if (DataService::update($this->table)) {
            $this->success("分类启用成功！", '');
        }
        $this->error("分类启用失败，请稍候再试！");
    }

    /**
     * 删除分类
     * @throws \think\Exception
     * @throws \think\exception\PDOException
     */
    public function del()
    {
        if (DataService::update($this->table)) {
            $this->success("分类删除成功！", '');
        }
        $this->error("分类删除失败，请稍候再试！");
    }
}